broadway: Add color nodes
authorAlexander Larsson <alexl@redhat.com>
Tue, 21 Nov 2017 20:56:06 +0000 (21:56 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 23 Nov 2017 09:48:29 +0000 (10:48 +0100)
gdk/broadway/broadway-protocol.h
gdk/broadway/broadway.js
gdk/broadway/broadwayd.c
gsk/gskbroadwayrenderer.c

index 3266330c4b086455ccae05380b24f41aba82c0e8..57b311026f8fdb64c36463275f80b193c766a954 100644 (file)
@@ -11,6 +11,7 @@ typedef struct  {
 typedef enum { /* Sync changes with broadway.js */
   BROADWAY_NODE_TEXTURE,
   BROADWAY_NODE_CONTAINER,
+  BROADWAY_NODE_COLOR,
 } BroadwayNodeType;
 
 typedef enum {
index 32406b070b497daeb930b7742b644f4f854971fc..eeb4bc7042700397b6a7f56dbb4839386085c506 100644 (file)
@@ -347,6 +347,31 @@ SwapNodes.prototype.handle_node = function(parent, node_data, data_pos)
             data_pos = this.handle_node(parent, node_data, data_pos);
         }
         break;
+
+    case 2:  // COLOR
+        var x = node_data[data_pos++];
+        var y = node_data[data_pos++];
+        var width = node_data[data_pos++];
+        var height = node_data[data_pos++];
+        var rgba = node_data[data_pos++];
+       var div = document.createElement('div');
+        div.style["position"] = "absolute";
+        div.style["left"] = x + "px";
+        div.style["top"] = y + "px";
+        div.style["width"] = width + "px";
+        div.style["height"] = height + "px";
+       a = (rgba >> 24) & 0xff;
+       r = (rgba >> 16) & 0xff;
+       g = (rgba >> 8) & 0xff;
+       b = (rgba >> 0) & 0xff;
+       if (a == 0)
+           c = "rgb(" + r + "," + g + "," + b + ")";
+       else
+           c = "rgba(" + r + "," + g + "," + b + "," + (a / 255.0) + ")";
+       div.style["background-color"] = c;
+        parent.appendChild(div);
+        break;
+
     default:
         alert("Unexpected node type " + type);
     }
index ebb00551688038e9d7f3ba5eb333c136a942fb6b..55a23b3ed0ab5fd69f06902342d8247706d284f1 100644 (file)
@@ -226,6 +226,9 @@ rewrite_node_textures (BroadwayClient *client,
 
   type = data[pos++];
   switch (type) {
+  case BROADWAY_NODE_COLOR:
+    pos += 5;
+    break;
   case BROADWAY_NODE_TEXTURE:
     data[pos+4] = GPOINTER_TO_INT (g_hash_table_lookup (client->textures,
                                                         GINT_TO_POINTER (data[pos+4])));
index fcc85831ad40d280c18fa920b1d182ad1a26e8b7..f22f404aec9fea7a9acc4a1b1ff585fcbdd0322d 100644 (file)
@@ -89,6 +89,24 @@ add_uint32 (GArray *nodes, guint32 v)
   g_array_append_val (nodes, v);
 }
 
+static guint32
+rgba_to_uint32 (const GdkRGBA *rgba)
+{
+  return
+    ((guint32)(0.5 + CLAMP (rgba->alpha, 0., 1.) * 255.) << 24) |
+    ((guint32)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.) << 16) |
+    ((guint32)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.) << 8) |
+    ((guint32)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.) << 0);
+}
+
+
+static void
+add_rgba (GArray *nodes, const GdkRGBA *rgba)
+{
+  guint32 c = rgba_to_uint32 (rgba);
+  g_array_append_val (nodes, c);
+}
+
 static void
 gsk_broadway_renderer_add_node (GskRenderer *self,
                                 GArray *nodes,
@@ -96,6 +114,10 @@ gsk_broadway_renderer_add_node (GskRenderer *self,
                                 GskRenderNode *node)
 {
   GdkDisplay *display = gsk_renderer_get_display (self);
+  int x = floorf (node->bounds.origin.x);
+  int y = floorf (node->bounds.origin.y);
+  int width = ceil (node->bounds.origin.x + node->bounds.size.width) - x;
+  int height = ceil (node->bounds.origin.y + node->bounds.size.height) - y;
 
   switch (gsk_render_node_get_node_type (node))
     {
@@ -115,12 +137,20 @@ gsk_broadway_renderer_add_node (GskRenderer *self,
       }
       return;
 
+    case GSK_COLOR_NODE:
+      {
+
+        add_uint32 (nodes, BROADWAY_NODE_COLOR);
+        add_uint32 (nodes, x);
+        add_uint32 (nodes, y);
+        add_uint32 (nodes, width);
+        add_uint32 (nodes, height);
+        add_rgba (nodes, gsk_color_node_peek_color (node));
+      }
+      return;
+
     default:
       {
-        int x = floorf (node->bounds.origin.x);
-        int y = floorf (node->bounds.origin.y);
-        int width = ceil (node->bounds.origin.x + node->bounds.size.width) - x;
-        int height = ceil (node->bounds.origin.y + node->bounds.size.height) - y;
         cairo_surface_t *surface;
         GdkTexture *texture;
         guint32 texture_id;